package main

import (
	"fmt"
	"net/http"
	"strings"

	"ginx/route"

	"github.com/gin-gonic/gin"
)

func main() {
	engine := gin.Default()
	gin.SetMode(gin.DebugMode)
	group := engine.Group("/")
	group.GET("timeout", func(c *gin.Context) {
		fmt.Println("xxxxxxxxxx")
		// 启动监听客户端断开的协程
		ctx := c.Request.Context()

		select {
		case <-ctx.Done():
			fmt.Println("done")
			return
		}
		c.JSON(http.StatusOK, gin.H{"message": "done"})
	})
	p := route.Proto{}
	f := route.File{}
	t := route.Test{}
	p.InitRoute(group)
	f.InitRoute(group)
	t.InitRoute(group)
	engine.Run(":8880")
}

func CreateHande(num int) []gin.HandlerFunc {
	funcs := make([]gin.HandlerFunc, 0)
	var bug strings.Builder
	for i := 0; i < num; i++ {
		funcs = append(funcs, func(context *gin.Context) {
			bug.WriteString("-")
			fmt.Println(bug.String(), i)
		})
	}
	return funcs
}
